package com.nccsjz.back.cardbuy.web;

import java.sql.SQLException;

import com.nccsjz.back.cardbuy.service.CardBuyService;
import com.nccsjz.base.BaseAction;
import com.nccsjz.pojo.CardBuy;
import com.nccsjz.utils.Page;
/**
 * CardBuyAction用于处理与集体购卡相关的表示层操作
 * 
 * @author Administrator
 *
 */
public class CardBuyAction extends BaseAction {

	/** cardbuy CardBuy 集体购卡信息 */
	private CardBuy cardbuy;
	
	/** 初始化存储分页数据的page对象 **/
	private Page page = new Page(40L);
	
	/** checkbox String[] 存储批量删除的订购信息编号 */
	private Long[] checkbox;
	
	
	
	
	/**
	 * add_CardBuy方法用于处理添加集体购卡信息的操作
	 * 
	 * @return
	 * @throws SQLException 
	 */
	public String add() throws SQLException{
		CardBuyService service = new CardBuyService(); 
		service.saveCardBuy(cardbuy);
		getSession().put("msg", "订购成功，我们会尽快与您联系！");
		return SUCCESS;
	}
	
	/**
	 * list方法用于列出未处理的集体购卡信息
	 * 
	 * @return
	 * @throws SQLException 
	 */
	public String list() throws SQLException{
		CardBuyService service = new CardBuyService();
		if(cardbuy == null){
			cardbuy = new CardBuy();
		}
		service.findCardBuy(cardbuy, page);
		if(page.getData().size() == 0){
			if(page.getPageNo() > 1L)
				page.setPageNo(page.getPageNo()-1);
			else if(page.getPageNo() == 1L)
				page.setPageNo(1L);			
		}
		service.findCardBuy(cardbuy, page);
		return "list";
	}
	
	/**
	 * delete方法用于处理删除指定的订购信息的操作
	 * 
	 * @return
	 * @throws SQLException 
	 */
	public String delete() throws SQLException{
		CardBuyService service = new CardBuyService();
		service.removeCardBuy(cardbuy.getRegid());		
		service.findCardBuy(cardbuy, page);
		if(page.getData().size() == 0){
			if(page.getPageNo() > 1L)
				page.setPageNo(page.getPageNo()-1);
			else if(page.getPageNo() == 1L)
				page.setPageNo(1L);			
		}
		service.findCardBuy(cardbuy, page);	
		addActionMessage("订购信息删除成功！");
		return "list";
	}

	/**
	 * deleteBatch方法用于批量删除指定的订购信息
	 * 
	 * @return
	 * @throws Exception 
	 */
	public String deleteBatch() throws Exception{
		CardBuyService service = new CardBuyService();
		if(checkbox != null){
			service.removeCardBuyBatch(checkbox);
		}
		service.findCardBuy(cardbuy, page);
		if(page.getData().size() == 0){
			if(page.getPageNo() > 1L)
				page.setPageNo(page.getPageNo()-1);
			else if(page.getPageNo() == 1L)
				page.setPageNo(1L);			
		}
		service.findCardBuy(cardbuy, page);	
		addActionMessage("订购信息批量删除成功！");
		return "list";
	}
	
	/**
	 * editCardBuy方法处理点击"编辑"跳转操作
	 * 
	 * @return
	 * @throws SQLException 
	 */
	public String editCardBuy() throws SQLException{
		CardBuyService service = new CardBuyService();
		if(cardbuy != null){
			this.cardbuy = service.findCardById(cardbuy.getRegid());
		}
		return "edit";
	}
	
	/**
	 * update方法处理订购信息更新操作
	 * 
	 * @return
	 * @throws SQLException
	 */
	public String updateCardBuy() throws SQLException{
		CardBuyService service = new CardBuyService();
		if(cardbuy != null){
			service.updateCardBuy(cardbuy);
		}
		service.findCardBuy(cardbuy, page);
		getSession().put("msg","订购信息更新成功！");
		return SUCCESS;
	}


	public CardBuy getCardbuy() {
		return cardbuy;
	}

	public void setCardbuy(CardBuy cardbuy) {
		this.cardbuy = cardbuy;
	}



	public Page getPage() {
		return page;
	}



	public void setPage(Page page) {
		this.page = page;
	}

	public Long[] getCheckbox() {
		return checkbox;
	}

	public void setCheckbox(Long[] checkbox) {
		this.checkbox = checkbox;
	}


	
	
	
	
	
	
	
}
